#!/bin/sh
cd $1

tar xfz update.tgz
rm update.tgz
rm update.tgz.sha256sum

lowercase(){
    echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
}

OS=`lowercase \`uname -s\``
MACH=`uname -m`

# Restart on OSX
if [ ${OS} = "darwin" ]; then
  launchctl unload /System/Library/LaunchAgents/com.domoticz.server.plist
  echo "Please standby ..."
  sleep 2
  launchctl load /System/Library/LaunchAgents/com.domoticz.server.plist
else
  sudo service domoticz.sh stop
  sudo systemctl stop domoticz.service
  echo "Please standby ..."
  sleep 2
  sudo service domoticz.sh start
  sudo systemctl start domoticz.service
fi
